package prototipo.server.logic.transaction;

import java.util.GregorianCalendar;
import java.util.List;

import prototipo.server.logic.exception.ExceptionLogic;
import prototipo.server.logic.item.Product;
import prototipo.server.logic.person.Client;
import prototipo.server.logic.person.ClientIF;

public class Output extends Transaction implements OutputIF {

	private ClientIF client;
	private long number;

	public Output(ClientIF client, long number, GregorianCalendar dateLatter,
			List<ItemPayIF> listItens, List<PaymentIF> payments)
			throws ExceptionLogic {
		super(dateLatter, listItens, payments);
		this.setClient(client);
		this.setNumber(number);
	}

	/**
	 * @return the client
	 */
	public ClientIF getClient() {
		return client;
	}

	/**
	 * @param client
	 *            the client to set
	 * @throws ExceptionLogic
	 */
	public void setClient(ClientIF client) throws ExceptionLogic {
		if (client == null)
			throw new ExceptionLogic("Cliente vazio.", new Throwable(
					"Client is null."));
		this.client = client;
	}

	/**
	 * @return the number
	 */
	public long getNumber() {
		return number;
	}

	/**
	 * @param number
	 *            the number to set
	 * @throws ExceptionLogic
	 */
	public void setNumber(long number) throws ExceptionLogic {
		if (number < 0)
			throw new ExceptionLogic("Numero de nota negativo.", new Throwable(
					"Number is negative."));
		this.number = number;
	}

	@Override
	protected boolean validateListItem(List<ItemPayIF> newListItens)
			throws ExceptionLogic {
		for (ItemPayIF itemPayIF : newListItens) {
			if (!(itemPayIF.getItem() instanceof Product)) {
				throw new ExceptionLogic(
						"Lista de itens deve conter apenas produtos.",
						new Throwable("ItemPay does not conten product."));
			}
		}
		return true;
	}

}
